package t4tools.lepath.query.eval;

import java.util.ArrayList;
import java.util.List;

public class PathExpression {

	private List<Step> steps = new ArrayList<>();
	private Context context = new Context();
	
	public Object evaluate(Object subject) {
		context.set(ContextKey.CURRENT_NODE, subject);
		
		for (Step step : steps) {
			Object evaluate = step.evaluate(context);
			context.set(ContextKey.CURRENT_NODE, evaluate);
		}
		return context.get(ContextKey.CURRENT_NODE);
	}
	
	public void addStep(Step step) {
		steps.add(step);
	}
	
	public void setVariable(String key, Object value) {
		context.setVar(key, value);
	}
}
